<template>
  <object
    id="ReportDesigner"
    type="application/x-grplugin6-designer"
    ref="obj"
    width="100%"
    height="100%"
  >
    <!-- <param name="LoadReportURL" :value="ReportUrl" /> -->
    <param name="SaveReportURL" value="" />
    <param name="SerialNo" :value="gr_SerialNo" />
    <param name="UserName" :value="gr_UserName" />
    <param name="DataUrl" value="" />
  </object>
  <skBrowserChoose
    v-model="openChooseDlg"
    :name="'setting_tableconfig_report_browser'"
    @close="openChooseDlg = false"
    @select="selectchoose"
  ></skBrowserChoose>
</template>
<script>
// require("@/utils/grhtml5-6.8-min");
import skBrowserChoose from "@/components/skBrowserChoose";
import tool from "@/utils/tool";
export default {
  components: { skBrowserChoose },
  props: {
    DataUrl: { type: String, default: "" },
  },
  data() {
    return {
      gr_UserName: "报表注册一",
      gr_SerialNo:
        "FA4N5EYHM9P87Y44PKW614V44FAC64KN1F6F39W9R3J26AI7E484JU45D2984P4G60VVA83C3F3A3UA5YJUX9X8WB3KV3N5L1UJ9G4C98BSUD5E44D6BG7F5L7AB5CUVA60F398KC0F6FBIZ9B4C98332C632R665D298TWTD6EFL88ZZUB549PB6BPVX9ZT9F5LKAE63RWQ6YJHN6AMWA5SWVQ9H3JN6BIHF6KD6M39BAF3Y79F6B0H88899C9901F6EFT49LP1G59HTD6K6JA9LTRB3AG7E68YI698J898A3UA5YJUX90WNB3SAUD63WG66YZPP7KIAE6PSV68EHUB3YNVD5B5IA9TDZX6F99F6K13883EZN8FA4N5KIIM9U6TB9KC0F6FBIZ9B4C98332C632R665D298STYB63WXC3A1396AMWA5SWVQ9H3JN6BIHF6KD6M3WAAF397EG6B0H88899C9901F6EFT49LP1G58HTD6XYVQ6S58C33QXE632R665D2984P4G6EVVA849TW48TYB6MNC56",
      Data: this.DataUrl,
      ReportDesigner: null,
      saveFlag: true,
      openChooseDlg: false,
    };
  },

  mounted() {
    this.ReportDesigner = this.$refs.obj;
    this.$nextTick(() => {
      this.getReport(this.$route.query.id);
    });
  },

  methods: {
    getReport(reportid) {
      this.$API.system.tableReport.info.get({ id: reportid }).then((res) => {
        this.ReportDesigner.LoadReportURL =
          res.data.url + "?version=" + new Date().getTime();
        this.ReportDesigner.OnOpenReport = this.OnOpenReport;
        this.ReportDesigner.OnSaveReport = this.OnSaveReport;
      });
    },
    OnSaveReport() {
      if (this.saveFlag) this.saveFlag = false;
      else return;
      //设置 DefaultAction 属性为 false，不执行控件本身的默认保存行为
      this.ReportDesigner.DefaultAction = false;
      //将设计器中的设计数据提交到报表对象
      this.ReportDesigner.Post();

      var LoadURL = this.$CONFIG.API_URL + "/system/tableReport/saveReport?";
      LoadURL += "temporaryToken=" + tool.data.get("TOKEN");
      LoadURL += "&id=" + this.$route.query.id;
      var success = this.ReportDesigner.Report.SaveToURL(encodeURI(LoadURL));

      if (success) {
        console.log(LoadURL);
      } else {
        console.log(success);
      }
      this.saveFlag = true;
    },
    OnOpenReport() {
      this.ReportDesigner.DefaultAction = false;
      console.log("OnOpen");
      this.openChooseDlg = true;
    },
    selectchoose(data) {
      this.openChooseDlg = false;
      if (this.$route.query.id != data[0].id) this.getReport(data[0].id);
    },
  },
};
</script>
<style></style>
